<template>
  <view class="new_task">
    <view class="main-item">
      <view class="btn-currency" @click="goRelease()" style="width: 150rpx"
        >任务发布</view
      >
      <view class="btn-currency" @click="search(true)" style="width: 150rpx"
        >我发布的</view
      >
    </view>
    <view class="main">
      <view class="main-item">
        <input type="text" placeholder="请输入关键词搜索" v-model="material" />
        <view class="btn-currency" @click="search()" style="width: 120rpx"
          >搜索</view
        >
      </view>
    </view>
    <view
      class="main"
      v-for="(
        {
          id,
          auditStatus_dictText,
          serialNo,
          address,
          material,
          contactsPerson,
          mobilePhone,
          createBy,
          signUp,
        },
        index
      ) in taskList"
      :key="index"
      @click="()=>goDetail(id)"
    >
      <view class="main-content">
        <view>任务状态：</view>
        <view>{{ auditStatus_dictText }}</view>
      </view>
      <view class="main-content">
        <view>任务编号：</view>
        <view>{{ serialNo }}</view>
      </view>
      <view class="main-content">
        <view>位置：</view>
        <view>{{ address }}</view>
      </view>
      <!-- <view class="rich-content">
				<rich-text :nodes="material"></rich-text>
			</view> -->
      <view class="main-content">
        <text>{{ material }}</text>
      </view>
      <view class="main-content">
        <view>联系人：</view>
        <view>{{ contactsPerson }}</view>
      </view>
      <view class="main-content">
        <view>联系电话：</view>
        <view>{{ mobilePhone }}</view>
      </view>
      <view class="main-content">
        <view>发布人：</view>
        <view>{{ createBy }}</view>
      </view>
      <view
        class="main-content main-item"
        style="justify-content: left; margin: 0"
      >
        <view class="btn-currency" style="margin: 0">
          {{
            signUp == "0" ? "我要报名" : signUp == "3" ? "人数已满" : "已报名"
          }}
        </view>
        <!-- <view class="main-content gray">
          <view v-if="signUp === 1">您已报名成功</view>
          <view v-else>您已通过审核</view>
        </view> -->
      </view>
    </view>

    <tabbar :current-index="1" />
  </view>
</template>

<script>
var _this;
import tabbar from "@/components/tab-bar";
import {taskList} from '@/api/tab2';

export default {
  components: {
    tabbar,
  },
  data() {
    return {
      // baseUrl: 'http://192.168.3.23:8085/jeecg-boot/',
      baseUrl: "http://weixiaokong.91xiaokong.com/jeecg-boot/",
      taskList: [],
      material: "",
      openId: "ogiDYs4eDr9DA2pofZeYsFQygtt4",
      nickname: "",
      headimgurl: "",
    };
  },
  onLoad() {
    _this = this;
	// uni.setStorage({
	//   key: "openid",
	//   data: "ogiDYs4eDr9DA2pofZeYsFQygtt4",
	//   success: function () {
	//     console.log("success");
	//   },
	// });
	debugger;
    let openid = uni.getStorageSync('openid');
    if (!openid) {
    	window.location.href = 'http://weixiaokong.91xiaokong.com/jeecg-boot/wx/mp/wxLoginShare?';
    }else{
    	_this.openId = openid
    }
    _this.getopenId();
  },
  onShow() {
    _this.search();
  },
  methods: {
    // 搜索
    async search(my=false) {
		debugger;
		const {material,openId,rescueType} = _this;
		let params = {
			material,openId,rescueType:"3" 
		}
		if(my) params = {
			...params, mine: openId
		}
		const {result:{records}} = await taskList(params);
		_this.taskList = records;
    },

    goRelease() {
      uni.navigateTo({ url: "../release_task/release_task" });
    },

    // 任务详情
    goDetail(id) {
      uni.navigateTo({
        url: `../task_detail/task_detail?id=${id}`,
      });
    },
	
    // 获取openid
    getopenId() {
      let url = window.location.href;
      _this.url = url;
      let url_1 = url.split("?"); // TODO: 鬼知道你在干嘛....像是梦游
      if (url_1.length > 1) {
        let url_2 = url_1[1].split("&");
        url_2.forEach(function (e) {
          if (e.indexOf("openid") > -1) {
            _this.openId = e.split("=")[1];
            uni.setStorage({
              key: "openid",
              data: _this.openId,
              success: function () {
                console.log("success");
              },
            });
          }
          if (e.indexOf("nickname") > -1) {
            _this.nickname = e.split("=")[1];
            uni.setStorage({
              key: "nickname",
              data: _this.nickname,
              success: function () {
                console.log("success");
              },
            });
          }
          if (e.indexOf("headimgurl") > -1) {
            _this.headimgurl = e.split("=")[1];
            uni.setStorage({
              key: "headimgurl",
              data: _this.headimgurl,
              success: function () {
                console.log("success");
              },
            });
          }
        });
      }
    },
  },
};
</script>

<style>
.new_task {
  padding-bottom: 140rpx;
  padding-top: 80rpx;
}

.main-item {
  display: flex;
  justify-content: space-around;
  line-height: 100rpx;
  flex-wrap: wrap;
  margin-bottom: 30rpx;
}

.main-item input {
  width: 70%;
  height: 60rpx;
  line-height: 60rpx;
  border: 2rpx solid #cccccc;
  border-radius: 30rpx;
  padding: 0 20rpx;
  margin: auto;
}

.main-item view {
  width: 150rpx;
  height: 60rpx;
  line-height: 40rpx;
  margin-top: 40rpx;
  margin-left: 50rpx;
  border-radius: 30rpx;
  font-size: 30rpx;
  padding: 10rpx;
  text-align: center;
  margin: auto;
}

.btn-currency {
	text-align: center;
	line-height: 30rpx;
  background-color: #b30002;
  color: #ffffff;
  border: none;
}

.main {
  width: 88%;
  margin: 0 auto;
  box-shadow: 0px 0px 30px 0px rgb(0 0 0 / 10%);
  border-radius: 20rpx;
  padding: 30rpx;
  margin-bottom: 30rpx;
  background-color: #fff;
  border: 2rpx #706d6c;
}

.main-content {
  display: flex;
  padding: 20rpx 0;
}

.gray {
  color: #999999;
}

.main-content view:first-of-type {
  white-space: nowrap;
}
</style>
